//
//  BGMineTableViewHeader.swift
//  Baga
//
//  Created by 飞王 on 16/12/28.
//  Copyright © 2016年 飞王. All rights reserved.
//

import UIKit
import SnapKit
import Toast_Swift
import SwiftyJSON
import HandyJSON

protocol BGMineHeaderDelegate: NSObjectProtocol {
    //登录代理方法
    func mineHaderLogin();
}

class BGMineTableViewHeader: UITableViewHeaderFooterView {
    
    weak var delegate: BGMineHeaderDelegate?
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier);
        setupView();
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    func setupView() {
        addSubview(icomView);
        
        icomView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX);
            make.top.equalTo(self.snp.top).offset(20);
            make.height.equalTo(80);
            make.width.equalTo(icomView.snp.height);
        }
        
        
        addSubview(loginButton);
        
        loginButton.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX);
            make.top.equalTo(icomView.snp.bottom).offset(5);
            make.width.equalTo(100);
            make.height.equalTo(30);
        }
        
    }
    
    @objc private func login() {
        delegate?.mineHaderLogin();
//        if delegate?.responds(to: #selector("mineHaderLogin"));
    }
    
    //MARK: - LazyLoad
    private lazy var icomView:UIButton = {
        let icomView = UIButton.init();
        icomView.layer.masksToBounds = true;
        icomView.layer.cornerRadius = 40;
        
        let icon = UIImage(named: "Icon-76");
        
        icomView.setImage(icon, for: .normal);
        
        icomView.addTarget(self, action: #selector(login), for: UIControlEvents.touchUpInside);
        
        return icomView;

    }();
    
    private lazy var loginButton:UIButton = {
        
        let loginButton = UIButton.init();
    
        loginButton.setTitle("点击登录", for: .normal);
        
        loginButton.titleLabel?.textAlignment = NSTextAlignment.center;
        
        loginButton.addTarget(self, action: #selector(login), for: UIControlEvents.touchUpInside);
        
        return loginButton;
    }();

}
